package com.hoperun.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhaolei
 * @date 2021/2/26 - 0:29
 */
@Controller
public class RequestController {
    @GetMapping("/goto")
    public String Goto(HttpServletRequest request){
        request.setAttribute("message", "成功");
        request.setAttribute("age", 25);
        return "forward:/success";
    }

    @ResponseBody
    @GetMapping("/success")
    public Map<String, Object> success(@RequestAttribute("message") String msg,
                                       @RequestAttribute("age") Integer age,
                                       HttpServletRequest request){
        Object object = request.getAttribute("age");
        Map map = new HashMap<>();
        map.put("msg",msg);
        map.put("age1111", object);
//        map.put("age:",age);


        return map;
    }
}
